package biz.impl;

import biz.EmpBiz;
import listener.StartTomcatListener;
import mapper.EmpMapper;
import org.apache.ibatis.session.SqlSession;
import org.example.bean.EmpInfo;
import org.example.bean.PageInfo;

import java.util.List;

public class EmpBizImpl implements EmpBiz {
    private EmpMapper em;
    private SqlSession session;

    public EmpBizImpl() {
        session = StartTomcatListener.ssf.openSession();
        em = session.getMapper(EmpMapper.class);
    }

    @Override
    public List<EmpInfo> findEmpByPage(int page) {
        PageInfo pi = new PageInfo(page,5);
        return em.findEmpByPage(pi);
    }

    @Override
    public int findEmpAllCount() {
        int count = em.findEmpAllCount();
        int page = count%5==0?(count/5):(count/5+1);
        return page;
    }

    @Override
    public EmpInfo findEmpById(int empNo) {
        return em.findEmpById(empNo);
    }

    @Override
    public void updateEmp(EmpInfo ei) {
        em.updateEmp(ei);
    }
}
